package middleware

import (
	"github.com/gin-gonic/gin"
	"webGin/untils"
	"net/http"
)

func Auth() gin.HandlerFunc {
	return func(c *gin.Context) {
		if untils.ValidToken(c.Request){
			c.Next()
			return
		}else {
			c.JSON(http.StatusUnauthorized,gin.H{
				"error":"Unauthorized",
			})
			c.Abort()
			return
		}
	}
}